import 'package:finance_app/generated/json/base/json_convert_content.dart';
import 'package:finance_app/generated/json/base/json_field.dart';
import 'package:finance_app/src/common/config.dart';
import 'package:finance_app/src/entities/setting_data_entity.dart';

class SettingInfoEntity with JsonConvert<SettingInfoEntity> {
  String language;
  @JSONField(name: "default_currency_code")
  String defaultCurrencyCode;
  @JSONField(name: "default_payment_type_id")
  dynamic defaultPaymentTypeId;
  @JSONField(name: "default_payment_term_id")
  dynamic defaultPaymentTermId;
  @JSONField(name: "tax_id")
  dynamic taxId;
  @JSONField(name: "date_format")
  String dateFormat;
  @JSONField(name: "number_formats")
  List<SettingInfoNumberFormats> numberFormats;
  SettingInfoTemplates templates;
  @JSONField(name: "unit_types")
  List<SettingDataUnitType> unitTypes;
  List<String> alerts;

  SettingDataTax get taxData => Config.currentCompany.enableGst == 1
      ? Config.settingData?.tax?.firstWhere(
          (element) => element.id == Config.settingInfo?.taxId,
          orElse: () => null)
      : Config.noneTax;

  SettingDataPaymentType get paymentType =>
      Config.settingData?.paymentType?.firstWhere(
          (element) => element.id == Config.settingInfo?.defaultPaymentTypeId,
          orElse: () => null);

  SettingDataCurrency get currencyCode =>
      Config.settingData?.currency?.firstWhere(
          (element) => element.key == Config.settingInfo?.defaultCurrencyCode,
          orElse: () => null);
}

class SettingInfoNumberFormats with JsonConvert<SettingInfoNumberFormats> {
  int id;
  @JSONField(name: "company_id")
  int companyId;
  String type;
  String prefix;
  String digit;
  int number;
  @JSONField(name: "created_at")
  String createdAt;
  @JSONField(name: "updated_at")
  String updatedAt;
}

class SettingInfoTemplates with JsonConvert<SettingInfoTemplates> {
  String invoice;
  String delivery;
  String quotation;
  @JSONField(name: "credit_note")
  String creditNote;
  @JSONField(name: "purchase_order")
  String purchaseOrder;
}
